package com.coffee.netty.connection;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author songkui
 * @since 2024/8/6
 */
public class ConnectionManager {
    private final Map<Long, Connection> connectionMap = new ConcurrentHashMap<>();

    private static final class ManagerHolder {
        static final ConnectionManager manager = new ConnectionManager();
    }

    public static ConnectionManager getInstance() {
        return ConnectionManager.ManagerHolder.manager;
    }

    public void put(Connection connection){
        connectionMap.put(connection.getId(), connection);
    }

    public void remove(Connection connection){
        connectionMap.remove(connection.getId());
    }

    public Connection getById(Long id){
        return connectionMap.get(id);
    }


}
